home *** CD-ROM | disk | FTP | other *** search
/ The Original Shareware 1.1 / The Original Shareware (WeMake CDs)(Volume 1.1)(CDs, Inc)(1993).iso / 19 / madtrb11.zip / GRADES.PAS < prev    next >
Pascal/Delphi Source File  |  1986-01-02  |  47KB  |  1,928 lines

  1. PROGRAM GRADES;
  2.  
  3. CONST
  4.   MAXRECORDS = 101;
  5.   MAXSIZE    = 100;      (*MAXSIZE := MAXRECORDS - 1*)
  6.   NAMESIZE   = 20;
  7.   headsize   = 50;
  8.   COMSIZE    = 40;
  9.  
  10. TYPE
  11.   diskstring  = string[2];
  12.   stringtype  = string [NAMESIZE];
  13.   setofchar   = set of char;
  14.   commandtype = string [COMSIZE];
  15.  
  16.   gradeptr = ^gradetype;
  17.     gradetype = record
  18.       title : stringtype;
  19.       grade : real;
  20.       ptr   : gradeptr;
  21.     end; (*gradetype*)
  22.  
  23.  
  24.   STUDENTTYPE = record
  25.     name   : stringtype;
  26.     hmwk   : gradeptr;
  27.     quiz   : gradeptr;
  28.     test   : gradeptr;
  29.     lab    : gradeptr;
  30.     final  : real;
  31.     ave    : real;
  32.     fptr   : integer;
  33.     bptr   : integer;
  34.   end; (*classtype*)
  35.  
  36.   STUDENTLIST = array [0 .. MAXSIZE] of STUDENTTYPE;
  37.  
  38.   link = ^hashstructure;
  39.     hashstructure = record
  40.       pos : integer;
  41.       ptr : link;
  42.     end;
  43.  
  44.   HASHTYPE = array [0 .. MAXSIZE] of link;
  45.  
  46. VAR
  47.   STUDENT       : STUDENTLIST ;
  48.   HASH          : HASHTYPE;
  49.   EMPTY,p,y     : INTEGER;
  50.   header        : string[headsize];
  51.   drive         : diskstring;
  52.   file_out      : boolean;
  53.   f             : TEXT;
  54.   name          : stringtype;
  55.   okset,nameset : setofchar;
  56.   beep          : char;
  57.  
  58. (******************************** INITIALIZE *******************************)
  59.  
  60. PROCEDURE INITIALIZE;
  61.  
  62. var
  63.   i,j : integer;
  64.  
  65. begin
  66.   for i := 0 TO MAXSIZE do begin
  67.     with STUDENT [i] do begin
  68.       name := '[';
  69.       hmwk   := nil;
  70.       quiz   := nil;
  71.       test   := nil;
  72.       lab    := nil;
  73.       final  := 0;
  74.       fptr   := i+1;
  75.       bptr   := 0;
  76.     end; (*with*)
  77.  
  78.     hash [i] := nil;
  79.   end; (* for i *)
  80.  
  81.   STUDENT [MAXSIZE].fptr := 0;
  82.   STUDENT [0].fptr := 0;
  83.   STUDENT [0].name := 'total pts: ';
  84.   EMPTY := 1;
  85. end; (*initialize*)
  86.  
  87. {--------------------------------------}
  88. procedure video (i : integer);
  89. begin
  90.   textcolor (i);
  91. end; { video }
  92.  
  93. {--------------------------------------}
  94. function getchar (okset : setofchar):char;
  95. var
  96.   c : char;
  97.  
  98. begin
  99.   read (kbd,c);
  100.   c := UpCase (c);
  101.   if not (c in okset) then write (beep)
  102.     else if c in [' '..'}'] then write (c);
  103.  
  104.   while not (c in okset) do begin
  105.     read (kbd,c);
  106.     c := UpCase (c);
  107.     if not (c in okset) then write (beep)
  108.       else if (c in [' '..'}']) then write (c);
  109.   end;  { while not good }
  110.   getchar := c;
  111. end;  { getchar }
  112.  
  113. {--------------------------------------}
  114. procedure getname (var s : stringtype; okset : setofchar);
  115. var
  116.   i     : integer;
  117.   s1    : string[1];
  118.   stemp : stringtype;
  119.  
  120. begin
  121.   s1 := ' ';
  122.   stemp := '';
  123.   s1[1] := getchar (okset + [#13]);
  124.   if s1[1] in okset then stemp := concat (stemp,s1);
  125.   while (s1[1]<>#13) and (length(stemp)<NAMESIZE) do begin
  126.     if length(stemp)=0 then s1[1] := getchar (okset + [#13])
  127.     else if length(stemp)=NAMESIZE then s1[1] := getchar ([#13,#8])
  128.       else s1[1] := getchar (okset + [#13,#8]);
  129.  
  130.     if s1[1] in okset then stemp := concat (stemp,s1)
  131.       else if s1[1]=#8 then begin
  132.         write (chr(8),' ',chr(8));
  133.         delete (stemp,length(stemp),1);
  134.       end  { else }
  135.   end; { while }
  136.  
  137.   if length(stemp)>0 then begin
  138.     s := stemp;
  139.     for i := (length(stemp)+1) to NAMESIZE do  s := concat(s,'.');
  140.   end
  141.   else write (s);
  142. end;
  143.  
  144. {--------------------------------------}
  145. procedure getpaper (var s : stringtype; okset : setofchar);
  146. var
  147.   i     : integer;
  148.   s1    : string[1];
  149.   stemp : stringtype;
  150.  
  151. begin
  152.   s1 := ' ';
  153.   stemp := '';
  154.   s1[1] := getchar (okset + [#13]);
  155.   if s1[1] in okset then stemp := concat (stemp,s1);
  156.   while (s1[1]<>#13) and (length(stemp) < NAMESIZE) do begin
  157.     if length(stemp)=0 then s1[1] := getchar (okset + [#13])
  158.     else if length(stemp)=NAMESIZE then s1[1] := getchar ([#13,#8])
  159.       else s1[1] := getchar (okset + [#13,#8]);
  160.  
  161.     if s1[1] in okset then stemp := concat (stemp,s1)
  162.       else if s1[1]=#8 then begin
  163.         write (chr(8),' ',chr(8));
  164.         delete (stemp,length(stemp),1);
  165.       end  { else }
  166.   end; { while }
  167.  
  168.   if length(stemp)>0 then begin
  169.     s := stemp;
  170.     for i := (length(stemp)+1) to NAMESIZE do  s := concat(' ',s);
  171.   end
  172.   else write (s);
  173. end;
  174.  
  175. {--------------------------------------}
  176. procedure getstring (var s : stringtype; okset : setofchar);
  177. var
  178.   i     : integer;
  179.   s1    : string[1];
  180.   stemp : stringtype;
  181.  
  182. begin
  183.   s1 := ' ';
  184.   stemp := '';
  185.   s1[1] := getchar (okset + [#13]);
  186.   if s1[1] in okset then stemp := concat (stemp,s1);
  187.   while s1[1]<>#13 do begin
  188.     if length(stemp)=0 then s1[1] := getchar (okset + [#13])
  189.     else if length(stemp)=80 then s1[1] := getchar ([#13,#8])
  190.       else s1[1] := getchar (okset + [#13,#8]);
  191.  
  192.     if s1[1] in okset then stemp := concat (stemp,s1)
  193.       else if s1[1]=#8 then begin
  194.         write (chr(8),' ',chr(8));
  195.         delete (stemp,length(stemp),1);
  196.       end  { else }
  197.   end; { while }
  198.  
  199.   if length(stemp)>0 then s := stemp
  200.     else write (s);
  201. end;
  202.  
  203. {--------------------------------------}
  204. procedure getint (com : commandtype; var int : integer);
  205. var
  206.   s        : stringtype;
  207.   i,result : integer;
  208.  
  209. begin
  210.   okset := (['-'] + ['0'..'9']);
  211.   repeat
  212.     write (com);
  213.     s := ''; result := 0;
  214.     getstring (s,okset);
  215.     if length(s)>0 then begin
  216.       val (s,i,result);
  217.       if result<>0 then begin video (30);
  218.         write (beep,' integer expected '); delay (2000); video (15);
  219.         delLine; clreol;
  220.       end; { if result <>0 }
  221.     end; {if length (s) >0 }
  222.   until result=0;
  223.  
  224.   if length(s)>0 then int := i
  225.     else write (int);
  226. end; { getint }
  227.  
  228. {--------------------------------------}
  229. procedure getreal (com : commandtype; var rl : real);
  230. var
  231.   r         : real;
  232.   result    : integer;
  233.   s         : stringtype;
  234.  
  235. begin
  236.   okset := (['-','.'] + ['0'..'9']);
  237.   repeat
  238.     write (com);
  239.     s := ''; result := 0;
  240.     getstring (s,okset);
  241.     if length(s)>0 then begin
  242.       val (s,r,result);
  243.       if result<>0 then begin video (30);
  244.         write (beep,' real expected '); delay (2000); video (15);
  245.         delLine; clreol;
  246.       end; { if result <>0 }
  247.     end; { if length(s) >0 }
  248.   until result=0;
  249.  
  250.   if length(s)>0 then rl := r
  251.     else write (rl);
  252. end; { getreal }
  253.  
  254. {--------------------------------------}
  255. function yes : boolean;
  256. var
  257.   c : char;
  258.  
  259. begin
  260.   c := getchar (['Y','N']);
  261.   if c='Y' then yes := true
  262.     else yes := false;
  263. end; { yes }
  264.  
  265. (********************************* COMPARE *********************************)
  266.  
  267. (* COMPARE =
  268.      -1 if term1 < term2
  269.       0 if term1 = term2
  270.       1 if term1 > term2
  271. *)
  272.  
  273. FUNCTION COMPARE (term1,term2 : stringtype):integer;
  274. begin
  275.   if (term1 > term2) then compare := 1
  276.     else if (term1 < term2) then compare := -1
  277.     else compare := 0;
  278. end; (* compare*)
  279.  
  280. (******************************* HASHID ************************************)
  281.  
  282. FUNCTION HASHNAME (term : stringtype):integer;
  283.  
  284. var
  285.   i,key : integer;
  286.  
  287. begin
  288.   key := 0;
  289.   for i := 1 to length(term) do key := key + ord (term[i]);
  290.   HASHNAME := trunc (MAXRECORDS * (key * 0.618034 - trunc (key*0.618034)));
  291. end; (*hash*)
  292.  
  293. (****************************** INSERTHASH *********************************)
  294.  
  295. PROCEDURE INSERTHASH (i : integer);
  296.  
  297. var
  298.   j : integer;
  299.   p : link;
  300.  
  301. begin
  302.   j := HASHNAME (STUDENT [i].name);
  303.   new (p);
  304.   p^.pos   := i;
  305.   p^.ptr   := HASH [j];
  306.   HASH [j] := p;
  307. end; (* INSERTHASH *)
  308.  
  309. (******************************** INSERT ***********************************)
  310.  
  311. PROCEDURE INSERT (i : integer);
  312.  
  313. var
  314.   j : integer;
  315.  
  316. begin
  317.   j     := STUDENT [0].fptr;
  318.  
  319.   while (COMPARE (STUDENT [j].name,STUDENT [i].name) <1) do
  320.     if (COMPARE (STUDENT [j].name,STUDENT [i].name) =0) then begin
  321.       writeln; video (30);
  322.       writeln (beep,'Student already entered');
  323.       writeln ('Addition of name aborted');
  324.       video (15); delay (2000);
  325.       exit;
  326.     end
  327.     else
  328.       j := STUDENT [j].fptr;
  329.  
  330.   EMPTY := STUDENT [i].fptr;
  331.   STUDENT [i].bptr := STUDENT [j].bptr;
  332.   STUDENT [i].fptr := STUDENT [STUDENT [j].bptr].fptr;
  333.   STUDENT [STUDENT [j].bptr].fptr := i;
  334.   STUDENT [j].bptr := i;
  335.  
  336.   INSERTHASH (i);
  337. end; (* insert *)
  338.  
  339. (****************************** ADDNAME ************************************)
  340.  
  341. PROCEDURE ADDNAME;
  342.  
  343. var
  344.   i : integer;
  345.  
  346. begin
  347.   clrscr;
  348.   i := EMPTY;
  349.   if i=0 then begin
  350.     writeln; video (30);
  351.     writeln (beep,'Maximum number of students already entered');
  352.     writeln ('Check manual for directions');
  353.     video(15); delay(2000);
  354.   end
  355.  
  356.   else with STUDENT [i] do begin
  357.     writeln;
  358.     write ('Enter student name: ');
  359.     name := '';
  360.     getname (name,nameset);
  361.     if (length(name)>0) then insert (i)
  362.       else name := '[';
  363.   end; (*else*)
  364. end; (*addname*)
  365.  
  366. (********************************* ENTERCLASS ****************************)
  367.  
  368. PROCEDURE ENTERCLASS;
  369.  
  370. var
  371.   i,num : integer;
  372.  
  373. begin
  374.   clrscr;
  375.   num := 0;
  376.   getint ('Number of students to be entered: ',num);
  377.   for i := 1 to num do
  378.     ADDNAME;
  379. end; (* enterclass *)
  380.  
  381. (******************************* FINDNAME *******************************)
  382.  
  383. PROCEDURE FINDNAME (term : stringtype;
  384.                     var found : boolean;
  385.                     var p,q   : link;
  386.                     var j : integer);
  387.  
  388. begin
  389.   j := HASHNAME (term);
  390.  
  391.   found := false;
  392.   q     := nil;
  393.   p     := HASH [j];
  394.  
  395.   while (p<>nil) and not found do
  396.     if (COMPARE (STUDENT [p^.pos].name,term) = 0) then
  397.       found := true
  398.     else begin
  399.       q := p;
  400.       p := p^.ptr;
  401.     end; (*else*)
  402. end; (* findname *)
  403.  
  404. (********************************* CHANGENAME ***************************)
  405.  
  406. PROCEDURE CHANGENAME;
  407.  
  408. var
  409.   term : stringtype;
  410.   i,j  : integer;
  411.   found: boolean;
  412.   p,q  : link;
  413.  
  414. begin
  415.   clrscr;
  416.   write ('Change which name? ');
  417.   term := '';
  418.   getName (term,nameset);
  419.   FindName (term,found,p,q,i);
  420.  
  421.   if not found then begin
  422.     video (30); writeln;
  423.     writeln (beep,term,' not found in class list');
  424.     video(15); delay (2000);
  425.   end
  426.  
  427.   else begin
  428.     j := p^.pos;
  429.     if q=nil then
  430.       HASH [i] := p^.ptr
  431.     else
  432.       q^.ptr := p^.ptr;
  433.  
  434.     writeln; writeln;
  435.     write ('Change name to? ');
  436.     getname (STUDENT [j].name,nameset);
  437.  
  438.     i := STUDENT [0].fptr;
  439.     while (COMPARE (STUDENT [i].name,STUDENT [j].name)<1) and (i<>0) do
  440.       i := STUDENT [i].fptr;
  441.  
  442.     STUDENT [STUDENT [j].bptr].fptr := STUDENT [j].fptr;
  443.     STUDENT [STUDENT [j].fptr].bptr := STUDENT [j].bptr;
  444.     STUDENT [j].bptr := STUDENT [i].bptr;
  445.     STUDENT [j].fptr := STUDENT [STUDENT [i].bptr].fptr;
  446.     STUDENT [STUDENT [i].bptr].fptr := j;
  447.     STUDENT [i].bptr := j;
  448.  
  449.     INSERTHASH (j);
  450.   end; (* else *)
  451. end; (* changename *)
  452.  
  453. (********************************** DELNAME *****************************)
  454.  
  455. PROCEDURE DELNAME;
  456.  
  457. var
  458.   i,j   : integer;
  459.   found : boolean;
  460.   term  : stringtype;
  461.   p,q   : link;
  462.  
  463. begin
  464.   clrscr;
  465.   write ('Delete which student? ');
  466.   term := '';
  467.   getname (term,nameset);
  468.  
  469.   FINDNAME (term,found, p,q,j);
  470.  
  471.   if not found then begin
  472.     writeln; video (30);
  473.     writeln (beep,term,' not in classlist - no deletion performed!');
  474.     delay (2000); video (15);
  475.   end (* if *)
  476.  
  477.   else begin
  478.     if q=nil then
  479.       HASH [j] := nil
  480.     else
  481.       q^.ptr := p^.ptr;
  482.  
  483.     i := p^.pos;
  484.     STUDENT [STUDENT [i].bptr].fptr := STUDENT [i].fptr;
  485.     STUDENT [STUDENT [i].fptr].bptr := STUDENT [i].bptr;
  486.     STUDENT [i].fptr := EMPTY;
  487.     STUDENT [i].name := '[';
  488.     dispose (p);
  489.     EMPTY := i;
  490.   end; (* else *)
  491. end; (* DELNAME *)
  492.  
  493. (*********************************** FindPaper **************************)
  494.  
  495. PROCEDURE FindPaper (var p,q   : gradeptr;
  496.                            j   : stringtype;
  497.                      var found : boolean);
  498.  
  499. begin
  500.   found := false;
  501.   q     := nil;
  502.  
  503.   while (p<>nil) and not found do
  504.     if (COMPARE (p^.title,j) <> 0) then begin
  505.       q := p;
  506.       p := p^.ptr;
  507.     end
  508.     else found := true;
  509. end; (* findpaper *)
  510.  
  511. (********************************** InsertGrade **************************)
  512.  
  513. PROCEDURE InsertGrade (var p,q,s : gradeptr;
  514.                            i,l   : integer;
  515.                            j     : stringtype);
  516.  
  517. (* input parameters -
  518.      p - pointer from FindPaper
  519.      i - array position of student
  520.      j - title of paper*)
  521.  
  522. var
  523.   g     : real;
  524.   found : boolean;
  525.  
  526. begin
  527.   with STUDENT [i] do begin
  528.     FindPaper (p,q,j,found);
  529.     g := p^.grade;
  530.     if l=1 then writeln (name,' ',g:4:1);
  531.     getreal (concat(name,' '),g);
  532.  
  533.     if found then begin
  534.       s := p;
  535.       if (p^.grade=0) or (g>0) then
  536.         p^.grade := g
  537.     end
  538.     else begin
  539.       new (s);
  540.       s^.title := j;
  541.       s^.grade := g;
  542.       s^.ptr   := p;
  543.     end; (* else *)
  544.   end; (* with *)
  545. end; (* InsertGrade *)
  546.  
  547. (*********************************** SETGRADE **************************)
  548.  
  549. PROCEDURE SETGRADE (i,l   : integer;
  550.                     j     : stringtype;
  551.                     var r : gradeptr);
  552.  
  553. var
  554.   p,q,s : gradeptr;
  555.  
  556. begin
  557.   with STUDENT [i] do begin
  558.     p := r;
  559.     InsertGrade (p,q,s,i,l,j);
  560.  
  561.     if q=nil then
  562.       r := s
  563.     else
  564.       q^.ptr := s;
  565.  
  566.   end; (* with *)
  567. end; (* setgrade *)
  568.  
  569. (****************************** GRADEMENU ********************************)
  570.  
  571. FUNCTION GRADEMENU:char;
  572. begin
  573.   clrscr;
  574.   writeln ('Select type of paper from list');
  575.   writeln;
  576.   writeln ('  H -- homework');
  577.   writeln ('  Q -- quiz');
  578.   writeln ('  L -- lab');
  579.   writeln ('  E -- hour exam');
  580.   writeln ('  F -- final exam');
  581.   writeln ('<cr>-- return to main menu');
  582.   writeln;
  583.   write ('Enter selection: ');
  584.   GRADEMENU := getchar (['H','Q','L','E','F',#13]);
  585. end; (*grademenu*)
  586.  
  587. (********************************* ENTERGRADE ***************************)
  588.  
  589. PROCEDURE ENTERGRADE (i : integer; k : char;
  590.                       j   : stringtype;
  591.                       l : integer);
  592.  
  593. begin
  594.   with STUDENT [i] do
  595.     case k of
  596.       'H' : SETGRADE (i,l,j,hmwk);
  597.  
  598.       'Q' : SETGRADE (i,l,j,quiz);
  599.  
  600.       'L' : SETGRADE (i,l,j,lab);
  601.  
  602.       'E' : SETGRADE (i,l,j,test);
  603.  
  604.       'F' : begin
  605.               writeln;
  606.               final := 0;
  607.               getreal (concat(name,' '),final);
  608.             end;
  609.     end; (*case*)
  610. end; (* entergrade *)
  611.  
  612. (********************************** GetGrade ****************************)
  613.  
  614. FUNCTION GetGrade (i : integer; k : char;
  615.                      j : stringtype):real;
  616.  
  617. var
  618.   p,q   : gradeptr;
  619.   found : boolean;
  620.  
  621. begin
  622.   with STUDENT [i] do
  623.     case k of
  624.       'H' : begin
  625.               p := hmwk;
  626.               FindPaper (p,q,j,found);
  627.               if not found then
  628.                 GetGrade := -1
  629.               else
  630.                 GetGrade := p^.grade;
  631.             end;
  632.  
  633.       'Q' : begin
  634.               p := quiz;
  635.               FindPaper (p,q,j,found);
  636.               if not found then
  637.                 GetGrade := -1
  638.               else
  639.                 GetGrade := p^.grade;
  640.             end;
  641.  
  642.       'L' : begin
  643.               p := lab;
  644.               FindPaper (p,q,j,found);
  645.               if not found then
  646.                 GetGrade := -1
  647.               else
  648.                 GetGrade := p^.grade;
  649.             end;
  650.  
  651.       'E' : begin
  652.               p := test;
  653.               FindPaper (p,q,j,found);
  654.               if not found then
  655.                 GetGrade := -1
  656.               else
  657.                 GetGrade := p^.grade;
  658.             end;
  659.       'F' : GetGrade := final;
  660.     end; (* case *)
  661. end; (* GetGrade *)
  662.  
  663. (******************************** PUTINCLASS ******************************)
  664.  
  665. PROCEDURE PUTINCLASS;
  666.  
  667. var
  668.   i,t : integer;
  669.   j   : stringtype;
  670.   c   : char;
  671.  
  672. begin
  673.   c := GRADEMENU;
  674.   clrscr;
  675.  
  676.   if c<>#13 then begin
  677.  
  678.     if c<>'F' then begin
  679.       write ('Title of paper: '); j := '';
  680.       getpaper (j,nameset+['0'..'9']); writeln;
  681.     end (* if *)
  682.  
  683.     else j := 'Final Exam';
  684.  
  685.     t := trunc (GetGrade (0,c,j));
  686.     if (t<=0) then
  687.       repeat
  688.         ENTERGRADE (0,c,j,0);
  689.         t := trunc (GetGrade (0,c,j));
  690.         if t=0 then
  691.           writeln ('Total cannot be zero -- try again');
  692.       until (t>0)
  693.     else with STUDENT [0] do
  694.       writeln (name,t);
  695.  
  696.     i := STUDENT [0].fptr;
  697.     repeat
  698.       writeln;
  699.       ENTERGRADE (i,c,j,0);
  700.       i := STUDENT [i].fptr;
  701.     until i=0;
  702.   end; (* if *)
  703. end; (* putinclass *)
  704.  
  705. (********************************** ENTERPERSON ****************************)
  706.  
  707. PROCEDURE ENTERPERSON;
  708.  
  709. var
  710.   i,t    : integer;
  711.   x,z    : link;
  712.   found  : boolean;
  713.   j,term : stringtype;
  714.   c      : char;
  715.  
  716. begin
  717.   clrscr;
  718.   write ('Which student? '); term := '';
  719.   getname (term,nameset);
  720.   FindName (term,found,x,z,i);
  721.  
  722.   if not found then begin
  723.     writeln; video(30);
  724.     writeln (beep,'Student not found'); video(15); delay(2000);
  725.   end (* if *)
  726.  
  727.   else begin
  728.     i := x^.pos;
  729.     c := GRADEMENU;
  730.     clrscr;
  731.  
  732.     if c<>#13 then begin
  733.       if c<>'F' then begin
  734.         write ('Title of paper: '); j := '';
  735.         getpaper (j,(nameset + ['0'..'9']));
  736.       end; (* if *)
  737.  
  738.       t := trunc (GetGrade (0,c,j));
  739.  
  740.       if t=-1 then begin
  741.         video(30); writeln;
  742.         writeln ('Paper not in file ');
  743.         video(15); delay(2000);
  744.       end
  745.       else
  746.         writeln;
  747.         ENTERGRADE (i,c,j,1);
  748.     end; (* if *)
  749.   end; (* else *)
  750. end; (* enterperson *)
  751.  
  752. (********************************* REMOVE ********************************)
  753.  
  754. PROCEDURE REMOVE;
  755.  
  756. var
  757.   p,q     : gradeptr;
  758.   i       : integer;
  759.   term    : stringtype;
  760.   found   : boolean;
  761.   c       : char;
  762.  
  763. begin
  764.   c := GRADEMENU;
  765.   clrscr;
  766.   write ('Remove which paper? ');
  767.   getpaper (term,nameset);
  768.  
  769.   i := 0;
  770.   repeat
  771.     with STUDENT [i] do begin
  772.       case c of
  773.         'H': begin
  774.                p := hmwk;
  775.                FindPaper (p,q,term,found);
  776.                if found then begin
  777.                  if q=nil then
  778.                    hmwk := p^.ptr
  779.                  else
  780.                    q^.ptr := p^.ptr;
  781.                  dispose (p);
  782.                end;
  783.              end;
  784.         'Q': begin
  785.                p := quiz;
  786.                FindPaper (p,q,term,found);
  787.                if found then begin
  788.                  if q=nil then
  789.                    quiz := p^.ptr
  790.                  else
  791.                    q^.ptr := p^.ptr;
  792.                  dispose(p);
  793.                end;
  794.              end;
  795.         'L': begin
  796.                p := lab;
  797.                FindPaper (p,q,term,found);
  798.                if found then begin
  799.                  if q=nil then
  800.                    lab := p^.ptr
  801.                  else
  802.                    q^.ptr := p^.ptr;
  803.                  dispose (p);
  804.                end;
  805.            end;
  806.         'E': begin
  807.                p := test;
  808.                FindPaper (p,q,term,found);
  809.                if found then begin
  810.                  if q=nil then
  811.                    test := p^.ptr
  812.                  else
  813.                    q^.ptr := p^.ptr;
  814.                  dispose (p);
  815.                end;
  816.            end;
  817.       end; (* case *)
  818.       i := fptr;
  819.     end; (* with *)
  820.   until (i=0);
  821.   if not found then begin
  822.     writeln; video(30);
  823.     writeln (beep,term,' not found');
  824.     delay (2000); video(15);
  825.   end; (* if *)
  826. end; (* remove *)
  827.  
  828. (********************************** WHO **********************************)
  829.  
  830. PROCEDURE WHO;
  831. var
  832.   c : char;
  833.  
  834. begin
  835.   clrscr;
  836.   writeln ('Do you wish to:');
  837.   writeln;
  838.   writeln ('  C -- Enter entire class');
  839.   writeln ('  I -- Change individual grade');
  840.   writeln ('  R -- Remove paper');
  841.   writeln ('<cr>-- Return to main menu');
  842.   writeln;
  843.   write ('Enter choice: ');
  844.   c := getchar (['C','I','R',#13]);
  845.  
  846.   case c of
  847.     'C' : PUTINCLASS;
  848.     'I' : ENTERPERSON;
  849.     'R' : REMOVE;
  850.   end; (*case*)
  851. end; (*who*)
  852.  
  853. (********************************* PRINTGRADES ****************************)
  854.  
  855. PROCEDURE PRINTGRADES (i : integer; var p,q : gradeptr; one : boolean);
  856.  
  857. var
  858.   a,t : real;
  859.  
  860. begin
  861.   a := 0;
  862.   t := 0;
  863.  
  864.   if q = nil then
  865.     t := 1;
  866.  
  867.   while (q<>nil) do begin
  868.       t := q^.grade + t;
  869.       q := q^.ptr;
  870.     end;
  871.  
  872.   with STUDENT [i] do
  873.     write (f,name:20);
  874.  
  875.   while (p<>nil) do begin
  876.     if one then begin
  877.       writeln(f);
  878.       write (f,p^.title);
  879.     end; (* if *)
  880.  
  881.     a := a + p^.grade;
  882.     write (f,p^.grade:5:1);
  883.     p := p^.ptr;
  884.  
  885.     if p=nil then
  886.       writeln (f,'   ave : ',(a*100/t):5:1);
  887.   end; (* while *)
  888. end; (* printgrades *)
  889.  
  890. (********************************* PRINTSTUDENT ****************************)
  891.  
  892. PROCEDURE PRINTSTUDENT (i : integer; c : char; one : boolean);
  893. var
  894.   p,q : gradeptr;
  895.  
  896. begin
  897.   with STUDENT [i] do begin
  898.     case c of
  899.       'H': begin
  900.              p := hmwk;
  901.              q := STUDENT [0].hmwk;
  902.              PRINTGRADES (i,p,q,one);
  903.            end;
  904.  
  905.       'Q' : begin
  906.               p := quiz;
  907.               q := STUDENT [0].quiz;
  908.               PRINTGRADES (i,p,q,one);
  909.             end;
  910.  
  911.       'L' : begin
  912.               p := lab;
  913.               q := STUDENT [0].lab;
  914.               PRINTGRADES (i,p,q,one);
  915.             end;
  916.  
  917.       'E' : begin
  918.               q := STUDENT [0].test;
  919.               p := test;
  920.               PRINTGRADES (i,p,q,one);
  921.             end;
  922.  
  923.       'F' : writeln (f,name,(100*final/STUDENT [0].final):5:1);
  924.     end; (* case *)
  925.   end; (* with *)
  926. end; (* printstudent *)
  927.  
  928. (********************************** TITLES *********************************)
  929.  
  930. PROCEDURE TITLES (q : gradeptr);
  931.  
  932. var
  933.   p : gradeptr;
  934.   i : integer;
  935.  
  936. begin
  937.   for i := 1 to NAMESIZE do begin
  938.     write (f,'                   ');
  939.     p := q;
  940.     while p<>nil do begin
  941.       write (f,'    ',p^.title [i]);
  942.       p := p^.ptr;
  943.     end; (* while *)
  944.     writeln(f);
  945.   end; (* for *)
  946.  
  947.   writeln(f);
  948.   with STUDENT [0] do begin
  949.     write (f,name:20);
  950.     p := q;
  951.     while p<>nil do begin
  952.       write (f,p^.grade:5:1);
  953.       p := p^.ptr;
  954.     end; (* while *)
  955.   end; (* with *)
  956.  
  957.   writeln (f);
  958.   writeln (f,'-------------------------------------------------------------------------');
  959. end; (* titles *)
  960.  
  961. (********************************* PRINTCLASS *****************************)
  962.  
  963. PROCEDURE PRINTCLASS;
  964. var
  965.   i : integer;
  966.   c : char;
  967.  
  968. begin
  969.   c := GRADEMENU;
  970.   clrscr;
  971.  
  972.   if c<>#13 then begin
  973.     case c of
  974.       'H' : TITLES (STUDENT [0].hmwk);
  975.       'Q' : TITLES (STUDENT [0].quiz);
  976.       'L' : TITLES (STUDENT [0].lab);
  977.       'E' : TITLES (STUDENT [0].test);
  978.     end; (* case *)
  979.  
  980.     i := STUDENT [0].fptr;
  981.     repeat
  982.       with STUDENT [i] do begin
  983.         PRINTSTUDENT (i,c,false);
  984.         i := fptr;
  985.         if (i mod(15) = 0) then begin
  986.           writeln; write ('To continue press return'); readln;
  987.           y := wherey-2; gotoxy (1,y);
  988.         end;
  989.       end; (* with *)
  990.     until (i=0);
  991.   end; (* if *)
  992. end; (* printclass *)
  993.  
  994. (******************************** PRINTPERSON ***************************)
  995.  
  996. PROCEDURE PRINTPERSON;
  997.  
  998. var
  999.   i     : integer;
  1000.   p     : gradeptr;
  1001.   x,z   : link;
  1002.   found : boolean;
  1003.   term  : stringtype;
  1004.   c     : char;
  1005.  
  1006. begin
  1007.   clrscr;
  1008.   write ('Which student? ');
  1009.   term := '';
  1010.   getname (term,nameset);
  1011.   FindName (term,found,x,z,i);
  1012.   if not found then begin
  1013.     video (30); writeln;
  1014.     writeln (beep,term,' not in class list');
  1015.     video (15); writeln;
  1016.   end
  1017.  
  1018.   else begin
  1019.     i   := x^.pos;
  1020.     c   := GRADEMENU;
  1021.     if c<>#13 then begin
  1022.       clrscr;
  1023.       PRINTSTUDENT (i,c,true);
  1024.     end; (* if *)
  1025.   end; (* else *)
  1026.   writeln; write ('To continue press return'); readln;
  1027. end; (* printperson *)
  1028.  
  1029. (********************************* EXAMINE *******************************)
  1030.  
  1031. PROCEDURE EXAMINE;
  1032. var
  1033.   j   : integer;
  1034.   p   : gradeptr;
  1035.   c   : char;
  1036.  
  1037.   procedure title;
  1038.  
  1039.   begin
  1040.     with STUDENT [j] do
  1041.       while p<>nil do begin
  1042.         writeln (f,p^.title,'--------',p^.grade:5:1);
  1043.         p := p^.ptr;
  1044.       end; (* while *)
  1045.   end; (* title *)
  1046.  
  1047. begin
  1048.   clrscr;
  1049.   writeln ('Do you wish to see:');
  1050.   writeln;
  1051.   writeln ('  N -- student names');
  1052.   writeln ('  H -- homework titles');
  1053.   writeln ('  Q -- quiz titles');
  1054.   writeln ('  L -- lab titles');
  1055.   writeln ('<cr>-- return to main menu');
  1056.   writeln;
  1057.   write ('Enter choice: ');
  1058.   c := getchar (['N','H','Q','L',#13]);
  1059.  
  1060.   clrscr;
  1061.   j := 0;
  1062.   case c of
  1063.     'N' : begin
  1064.           writeln (f,'STUDENT':10);
  1065.           j := STUDENT [0].fptr;
  1066.           repeat
  1067.             writeln (f,STUDENT [j].name);
  1068.             j := STUDENT [j].fptr;
  1069.           until (j=0);
  1070.         end;
  1071.  
  1072.     'H' : begin
  1073.           writeln (f,'HOMEWORK TITLES     TOTAL POINTS');
  1074.           p := STUDENT [j].hmwk;
  1075.           title;
  1076.         end;
  1077.  
  1078.     'Q' : begin
  1079.           writeln (f,'QUIZ TITLES         TOTAL POINTS');
  1080.           p := STUDENT [j].quiz;
  1081.           title;
  1082.         end;
  1083.  
  1084.     'L' : begin
  1085.           writeln (f,'LAB TITLES          TOTAL POINTS');
  1086.           p := STUDENT [j].lab;
  1087.           title;
  1088.         end;
  1089.   end; (* case *)
  1090.   writeln; write ('To continue press return'); readln;
  1091. end; (* examine *)
  1092.  
  1093. {--------------------------------------}
  1094. {
  1095. Source: "TIMESTAMP and KBIN for the IBM-PC", TUG Lines Volume I Issue 2
  1096. Author: Karl Gerhard
  1097. Date:   7/5/84
  1098. Application: PC-DOS, MS-DOS
  1099. }
  1100.  
  1101. type
  1102.   stdstr = string[80];
  1103.  
  1104.   RecPack = record
  1105.      AX,BX,CX,DX,BP,SI,DI,DS,ES,FLAG:integer;
  1106.   end;
  1107.  
  1108. var
  1109.   regs:RecPack;
  1110.   ch:char;
  1111.  
  1112. {------------------------}
  1113. function StrInt(n:integer):stdstr;
  1114.   { return a string with the integer in ASCII }
  1115. var s:string[6];
  1116. begin
  1117.   str(n,s);
  1118.   strint := s;
  1119. end;
  1120.  
  1121. {------------------------}
  1122. procedure CallDos(fcn:integer);
  1123.   { execute DOS fcn# call }
  1124. begin
  1125.   with regs do begin
  1126.     ax := fcn;
  1127.     MsDos(regs);
  1128.   end; { with }
  1129.  end;
  1130.  
  1131. {------------------------}
  1132. function timestamp:stdstr;
  1133.   { return string of "MON DAY YEAR TIME" }
  1134. type mot = array[1..12] of string[3];
  1135. const mon:mot = ( 'JAN','FEB','MAR','APR','MAY','JUN',
  1136.                   'JUL','AUG','SEP','OCT','NOV','DEC');
  1137. var tsret:stdstr; hr:integer;   ampm:string[2]; Min : string[2];
  1138. begin
  1139.   CallDos($2A00);
  1140.   with regs do begin
  1141.     tsret :=  mon[Hi(DX)] +' '+ strint(Lo(DX)) +','+ strint(CX)+ '  ';
  1142.  
  1143.     CallDos($2C00);
  1144.     hr := Hi(cx);
  1145.     if hr > 11 then ampm := 'pm'
  1146.       else ampm := 'am';
  1147.     if hr > 12 then hr := hr - 12;
  1148.     min := strint (Lo(cx));
  1149.     if length(min)=1 then min := concat('0',min);
  1150.     timestamp := tsret + (strint(hr) ) + ':' + min + ampm;
  1151.   end;  { with }
  1152. end;
  1153.  
  1154. {-------------------------------------}
  1155. procedure Get_dir;
  1156.  
  1157. { This program should display the disk directory from with any turbo program. }
  1158.  
  1159. type
  1160.   dir_str = string[12];
  1161.   regpack = record
  1162.     ax,bx,cx,dx,bp,si,di,ds,es,flags : integer;
  1163.   end; { recpack }
  1164.  
  1165.   var
  1166.     name1,name2 : dir_str;
  1167.     found       : boolean;
  1168.     j           : integer;
  1169.  
  1170. {-------------------------------------}
  1171. procedure Find_dta ( var dta_seg,dta_ofs : integer);
  1172. var
  1173.   recpack : regpack;
  1174.  
  1175. begin
  1176.   with recpack do begin
  1177.     ax := $2F shl 8;
  1178.     MsDos(recpack);
  1179.     dta_seg := es;
  1180.     dta_ofs := bx;
  1181.   end; { with }
  1182. end; { Find_dta }
  1183.  
  1184. {-------------------------------------}
  1185. function get_filename : dir_str;
  1186. var
  1187.   i,dta_seg,dta_ofs : integer;
  1188.   result            : dir_str;
  1189.   c                 : char;
  1190.  
  1191. begin
  1192.   Find_dta (dta_seg,dta_ofs);
  1193.   result := '';
  1194.   i := 30;
  1195.   c := chr (mem[dta_seg:dta_ofs+i]);
  1196.   while c<>chr(0) do begin
  1197.     result := concat (result,c);
  1198.     i := i + 1;
  1199.     c := chr (mem[dta_seg:dta_ofs+i]);
  1200.   end; { while }
  1201.   get_filename := result;
  1202. end; { get_filename }
  1203.  
  1204. {-------------------------------------}
  1205. procedure dir_first (   source : dir_str;
  1206.                     var result : dir_str;
  1207.                     var found  : boolean);
  1208.  
  1209. var
  1210.   recpack : regpack;
  1211.   flg     : byte;
  1212.  
  1213. begin
  1214.   source := concat (source,chr(0));
  1215.   with recpack do begin
  1216.     ax := $4E shl 8;
  1217.     ds := (seg(source));
  1218.     dx := (ofs(source) + 1);
  1219.   end;
  1220.  
  1221.   MsDos(recpack);
  1222.   result := '';
  1223.   flg := recpack.flags and 1;
  1224.   if flg = 0 then begin
  1225.     found := true;
  1226.     result := get_filename;
  1227.   end { if found }
  1228.   else found := false;
  1229. end; { dir_first }
  1230.  
  1231. {-------------------------------------}
  1232. procedure dir_next (   source : dir_str;
  1233.                    var result : dir_str;
  1234.                    var found  : boolean);
  1235.  
  1236. var
  1237.   recpack : regpack;
  1238.   flg     : byte;
  1239.  
  1240. begin
  1241.   source := concat (source,chr(0));
  1242.   with recpack do begin
  1243.     ax := $4F shl 8;
  1244.     ds := (seg(source));
  1245.     dx := (ofs(source)+1);
  1246.   end; { with }
  1247.  
  1248.   MsDos (recpack);
  1249.   result := '';
  1250.   flg := recpack.flags and 1;
  1251.   if flg=0 then begin
  1252.     found := true;
  1253.     result := get_filename;
  1254.   end
  1255.   else found := false;
  1256. end;
  1257.  
  1258. {----------  MAIN PROGRAM  -----------}
  1259. begin
  1260.   clrscr; drive := '';
  1261.   write ('Dir mask: '); drive[1] := getchar(['A','B','C','D']);
  1262.   drive[2] := ':';
  1263.   name1 := concat (concat(drive[1],drive[2]),'*.*');
  1264.   dir_first (name1,name2,found); writeln; writeln;
  1265.   if found then begin
  1266.     write (name2:15);
  1267.     j := 1;
  1268.     repeat
  1269.       j := j + 1;
  1270.       dir_next (name1,name2,found);
  1271.       if found then write (name2:15);
  1272.       if j = 4 then begin writeln; j := 0; end;
  1273.     until not found;
  1274.   end;
  1275.   window (1,18,80,25);
  1276. end; { procedure get_dir }
  1277.  
  1278. {--------------------------------------}
  1279. procedure rename (var name : stringtype);
  1280. var
  1281.   c            : char;
  1282.   i,j          : integer;
  1283.  
  1284. begin
  1285.   clrscr;
  1286.   i := length (name);
  1287.   j := pos (':',name);
  1288.   if j=0 then begin
  1289.     if i>7 then delete (name,9,(i-8));
  1290.     name := concat (concat(drive[1],drive[2]),name);
  1291.   end { if no semicolon }
  1292.   else if j<>2 then begin
  1293.     delete (name,j,1);
  1294.     if i>7 then delete (name,9,(i-8));
  1295.     name := concat (drive,name);
  1296.   end; { if semicolon wrong }
  1297.   i := length (name);
  1298.   j := pos('.',name);
  1299.   if j=0 then
  1300.     name := concat (name,'.dat')
  1301.   else if j<>(i-3) then
  1302.     delete (name,(j+4),i);
  1303. end; { rename }
  1304.  
  1305. (********************************** SAVE ******************************)
  1306. PROCEDURE SAVE;
  1307. var
  1308.   v         : integer;
  1309.   ok,destroy: boolean;
  1310.   i         : integer;
  1311.  
  1312.   procedure putfield (r : gradeptr);
  1313.  
  1314.   var
  1315.     p : gradeptr;
  1316.     j : integer;
  1317.  
  1318.   begin
  1319.     p := r;
  1320.     while p<>nil do begin
  1321.       writeln (f,p^.title:20,' ',p^.grade);
  1322.       p := p^.ptr;
  1323.     end; (* while *)
  1324.     writeln (f,' [':20,0:4);
  1325.   end; (* putfield *)
  1326.  
  1327. begin
  1328.   get_dir;
  1329.   okset := ([':','_','.','\'] + ['A'..'Z'] + ['0'..'9']);
  1330.   repeat
  1331.     clrscr;
  1332.     destroy := true;
  1333.     write('Output filename : '); name := '';
  1334.     getstring (name,okset);
  1335.     if (length (name)=0) then begin
  1336.       window (1,1,80,25); exit;
  1337.     end;
  1338.     rename (name);
  1339.     assign(f,name);
  1340. {$i-} reset(f); {$i+}
  1341.     ok := (ioresult=0);
  1342.     if ok then begin
  1343.       clrscr; delLine; video (30);
  1344.       writeln (beep,name,' already exist on disk'); video (15);
  1345.       writeln; write ('Do you wish to destroy file? (Y/N) ');
  1346.       if not yes then destroy := false
  1347.         else ok := false;
  1348.       close (f);
  1349.     end; { if file exist }
  1350.     close (f);
  1351.   until not ok;
  1352.  
  1353.   if destroy then begin
  1354.     video (30);
  1355.     writeln; writeln ('Writing to disk');
  1356.     rewrite (f);
  1357.     writeln (f,EMPTY);
  1358.     i := 0;
  1359.     while (i<=MAXSIZE) and (STUDENT[i].name<>'[') do begin
  1360.       with STUDENT[i] do begin
  1361.         writeln (f,name:20,fptr:10,bptr:10);
  1362.         putfield (hmwk);
  1363.         putfield (quiz);
  1364.         putfield (lab);
  1365.         putfield (test);
  1366.         writeln (f,final);
  1367.       end; (* with *)
  1368.       i := i + 1;
  1369.     end; (* while *);
  1370.     video (15);
  1371.     close (f);
  1372.     window (1,1,80,25);
  1373.   end; (* if *)
  1374. end; (* save *)
  1375.  
  1376. (******************************* RETRIEVE ********************************)
  1377. PROCEDURE RETRIEVE;
  1378. var
  1379.   i,j,k,l : integer;
  1380.   ok      : boolean;
  1381.   c       : char;
  1382.  
  1383.   procedure getfield (var p : gradeptr);
  1384.   var
  1385.     s : gradeptr;
  1386.  
  1387.   begin
  1388.     p := nil;
  1389.     new (s);
  1390.     readln (f,s^.title,s^.grade);
  1391.     while (s^.title[20] <> '[') and not eof(f) do begin
  1392.       s^.ptr := p;
  1393.       p := s;
  1394.       new (s);
  1395.       readln (f,s^.title,s^.grade);
  1396.     end; (* while *)
  1397.   end; (* getfield *)
  1398.  
  1399. begin
  1400.   okset := ([':','_','.','\'] + ['A'..'Z'] + ['0'..'9']);
  1401.   get_dir;
  1402.   repeat
  1403.     clrscr;
  1404.     write('Input filename : '); name := '';
  1405.     getstring (name,okset);
  1406.     if (length(name)=0) then begin
  1407.       window (1,1,80,25); exit;
  1408.     end;
  1409.     rename (name);
  1410.     assign(f,name);
  1411. {$i-} reset(f); {$i+}
  1412.     ok := (ioresult=0);
  1413.     if not ok then begin
  1414.       writeln; video (30);
  1415.       writeln (beep,'ERROR --- ',name,' not on disk'); video(15);
  1416.       ok := false; delay(2000);
  1417.     end; { if file exist }
  1418.   until ok;
  1419.   clrscr; video (30);
  1420.   writeln ('  Please wait --- reading input file'); video (15);
  1421.   for i := 0 to MAXSIZE do
  1422.     HASH [i] := nil;
  1423.  
  1424.   readln (f,EMPTY);
  1425.   i := 0;
  1426.   while not eof(f) do begin
  1427.     with STUDENT [i] do begin
  1428.       readln (f,name,fptr,bptr);
  1429.       getfield (hmwk);
  1430.       getfield (quiz);
  1431.       getfield (lab);
  1432.       getfield (test);
  1433.       readln (f,final);
  1434.     end; (* with *)
  1435.     INSERTHASH (i);
  1436.     i := i+1;
  1437.   end; (* while *)
  1438.  
  1439.   for i := EMPTY to MAXSIZE do with STUDENT[i] do begin
  1440.     name := '['; fptr := i+1; bptr := 0; final := 0;
  1441.   end; { for i }
  1442.   STUDENT[i].fptr := 0;
  1443.   close (f);
  1444.   window (1,1,80,25);
  1445. end; (* RETRIEVE *)
  1446.  
  1447. {--------------------------------------}
  1448. procedure files;
  1449. var
  1450.   v         : integer;
  1451.   ok,destroy: boolean;
  1452.   i         : integer;
  1453.  
  1454. begin
  1455.   get_dir;
  1456.   okset := ([':','_','.','\'] + ['A'..'Z'] + ['0'..'9']);
  1457.   repeat
  1458.     clrscr;
  1459.     destroy := true;
  1460.     write('Output filename : '); name := '';
  1461.     getstring (name,okset);
  1462.     if (length (name)=0) then begin
  1463.       window (1,1,80,25); exit;
  1464.     end;
  1465.     rename (name);
  1466.     assign(f,name);
  1467. {$i-} reset(f); {$i+}
  1468.     ok := (ioresult=0);
  1469.     if ok then begin
  1470.       clrscr; delLine; video (30);
  1471.       writeln (beep,name,' already exist on disk'); video (15);
  1472.       writeln; write ('Do you wish to destroy file? (Y/N) ');
  1473.       if not yes then destroy := false
  1474.         else ok := false;
  1475.       close (f);
  1476.     end; { if file exist }
  1477.     close (f);
  1478.   until not ok;
  1479.  
  1480.   if destroy then begin
  1481.     video (30);
  1482.     writeln; writeln ('Writing to disk');
  1483.     rewrite (f);
  1484.     file_out := true;
  1485.     video (15);
  1486.     window (1,1,80,25);
  1487.   end;
  1488. end;
  1489.  
  1490. (*********************************** AVERAGE *****************************)
  1491.  
  1492. PROCEDURE AVERAGE;
  1493. var
  1494.   i,j,num        : integer;
  1495.   yn             : char;
  1496.   ha,qa,la,ta    : real;
  1497.   wh,wq,wl,wt,wf : real;
  1498.   th,tq,tl,tt,tf : real;
  1499.   grades         : array [0 .. 100] of integer;
  1500.  
  1501.   function avegrade (i : integer;
  1502.                      r : gradeptr):real;
  1503.   var
  1504.     a : real;
  1505.     p : gradeptr;
  1506.  
  1507.   begin
  1508.     a := 0;
  1509.     p := r;
  1510.     while p<>nil do
  1511.       with STUDENT [i] do begin
  1512.         a := a + p^.grade;
  1513.         p := p^.ptr;
  1514.       end; (* while *)
  1515.     if a=0 then
  1516.       a := 0.000001;
  1517.     avegrade := a;
  1518.   end;
  1519.  
  1520. begin
  1521.   for i := 0 to 100 do
  1522.     grades [i] := 0;
  1523.  
  1524.   clrscr;
  1525.   writeln ('Enter overall weights');
  1526.   writeln; wh := 0;
  1527.   getreal ('homework: ',wh);
  1528.   wq := 0;
  1529.   getreal ('    quiz: ',wq);
  1530.   wl := 0;
  1531.   getreal ('     lab: ',wl);
  1532.   wt := 0;
  1533.   getreal ('    test: ',wt);
  1534.   wf := 0;
  1535.   getreal ('   final: ',wf);
  1536.  
  1537.   clrscr;
  1538.   if not file_out then
  1539.     writeln (f,'   NAME              HMWK  QUIZ   LAB  TEST  FINAL  AVERAGE');
  1540.  
  1541.   with STUDENT [0] do begin
  1542.     th := avegrade (0,hmwk);
  1543.     tq := avegrade (0,quiz);
  1544.     tl := avegrade (0,lab);
  1545.     tt := avegrade (0,test);
  1546.     if final=0 then
  1547.       tf := 1
  1548.     else
  1549.       tf := final;
  1550.     i  := fptr;
  1551.   end; (* with *)
  1552.  
  1553.   num := 0;
  1554.   repeat
  1555.     with STUDENT [i] do begin
  1556.       ave := 0;
  1557.       ha := avegrade (i,hmwk)*100/th;
  1558.       qa := avegrade (i,quiz)*100/tq;
  1559.       la := avegrade (i,lab)*100/tl;
  1560.       ta := avegrade (i,test)*100/tt;
  1561.       ave := (wh*ha + wq*qa + wl*la + wt*ta)/100 + wf*final/tf;
  1562.       if (round(ave) in [0 .. 100]) then begin
  1563.         num := num + 1;
  1564.         grades [round (ave)] := grades [round (ave)] + 1;
  1565.       end; (* if *)
  1566.  
  1567.       writeln (f,name:20,ha:5:1,qa:6:1,la:6:1,ta:6:1,(final*100/tf):7:1,ave:9:1);
  1568.       i := fptr;
  1569.       if not file_out then
  1570.         if (i mod(15) = 0) then begin
  1571.           writeln; write ('To continue press return'); readln;
  1572.           y := wherey - 2; gotoxy (1,y);
  1573.         end;
  1574.     end; (* with *)
  1575.   until (i=0);
  1576.   if not file_out then begin
  1577.   writeln (f); delline;
  1578.   write ('Frequency plot? ');
  1579.   if yes then begin
  1580.     clrscr;
  1581.     i := 100;
  1582.     while (grades [i] = 0) and (i>0) do
  1583.       i := i-1;
  1584.  
  1585.     while (num>0) and (i>0) do begin
  1586.       write (f,i,' ',chr(124),' ');
  1587.       for j := 1 to grades [i] do
  1588.         write (f,'*');
  1589.       writeln (f);
  1590.       num := num - grades [i];
  1591.       i := i - 1;
  1592.     end; (* while *)
  1593.     writeln; write ('To continue press return'); readln;
  1594.   end; (* if *)
  1595.   end;
  1596. end; (* average *)
  1597.  
  1598. {------------------- get_print ---------------------}
  1599. procedure get_print;
  1600. var
  1601.   c : char;
  1602.   i,code : integer;
  1603.  
  1604. begin
  1605.   clrscr;
  1606.   writeln ('Select printer options');
  1607.   writeln;
  1608.   writeln ('TYPE STYLE');
  1609.   writeln (' 1  - Pica');
  1610.   writeln (' 2  - Elite');
  1611.   writeln (' 3  - Compressed pica');
  1612.   writeln (' 4  - Compressed elite');
  1613.   writeln;
  1614.   write ('Enter Choice --> '); c := getchar (['1','2','3','4']);
  1615.   val(c,i,code);
  1616.   writeln; writeln;
  1617.   write ('Skip over margin? (Y/N) --> '); c := getchar (['Y','N']);
  1618.   if c='Y' then begin p := 60; i := 4 + i; end else p := 66;
  1619.   writeln; writeln; write ('Page header --> '); readln (header);
  1620.  
  1621.   case i of
  1622.     1  : write (lst,chr(18),chr(27),'P');
  1623.     2  : write (lst,chr(18),chr(27),'M');
  1624.     3  : write (lst,chr(15),chr(27),'P');
  1625.     4  : write (lst,chr(15),chr(27),'M');
  1626.     5  : write (lst,chr(27),'N',chr(6),chr(18),chr(27),'P');
  1627.     6  : write (lst,chr(27),'N',chr(6),chr(18),chr(27),'M');
  1628.     7  : write (lst,chr(27),'N',chr(6),chr(15),chr(27),'P');
  1629.     8  : write (lst,chr(27),'N',chr(6),chr(15),chr(27),'M');
  1630.   end;
  1631.   for i := length(header) to headsize do header := concat(header,' ');
  1632. end;
  1633.  
  1634. (********************************* PRINT *********************************)
  1635.  
  1636. PROCEDURE PRINT;
  1637. var
  1638.   i : char;
  1639.  
  1640. begin
  1641.   clrscr;
  1642.   file_out := false;
  1643.   write ('(S) creen or (P) rinter or (F)ile? '); i := getchar (['S','P','F',#13]);
  1644.   case i of
  1645.     'S' : assign (f,'con:');
  1646.     'P' : begin
  1647.             assign (f,'lst:');
  1648.             get_print;
  1649.             writeln (f,' ',header:headsize,'    ',timestamp);
  1650.           end;
  1651.     'F' : begin
  1652.             files;
  1653.             if length(name)=0 then exit;
  1654.             average;
  1655.             exit;
  1656.           end;
  1657.     #13 : exit;
  1658.   end;
  1659.   if not file_out then reset (f);
  1660.   clrscr;
  1661.   writeln ('Do you wish to see:');
  1662.   writeln;
  1663.   writeln ('  T -- T(itles');
  1664.   writeln ('  C -- C(lass grades (one field)');
  1665.   writeln ('  I -- I(ndividual''s grade');
  1666.   writeln ('  A -- class (A)verages (all fields)');
  1667.   writeln ('<cr>-- return to main menu');
  1668.   writeln;
  1669.   write ('Enter choice: ');
  1670.   i := getchar (['A','T','C','I',#13]);
  1671.  
  1672.   case i of
  1673.     'T' : EXAMINE;
  1674.     'C' : PRINTCLASS;
  1675.     'I' : PRINTPERSON;
  1676.     'A' : AVERAGE;
  1677.     #13 : exit;
  1678.   end; (* case *)
  1679.   write (f,chr(12));
  1680.   close (f);
  1681. end; (* print *)
  1682.  
  1683. (*********************************** NAME *******************************)
  1684.  
  1685. PROCEDURE NAMES;
  1686.  
  1687. var
  1688.   c : char;
  1689.  
  1690. begin
  1691.   clrscr;
  1692.   writeln ('Select option:');
  1693.   writeln;
  1694.   writeln ('  E -- enter names');
  1695.   writeln ('  C -- change name');
  1696.   writeln ('  D -- delete name');
  1697.   writeln ('<cr>-- return to main menu');
  1698.   writeln;
  1699.   write ('Enter choice: ');
  1700.   c := getchar (['E','C','D',#13]);
  1701.  
  1702.   case c of
  1703.     'E' : ENTERCLASS;
  1704.     'C' : CHANGENAME;
  1705.     'D' : DELNAME;
  1706.   end; (* case *)
  1707. end; (* name *)
  1708.  
  1709. procedure get_file (v:stringtype);
  1710. var
  1711.   i,j,k,l : integer;
  1712.   ok      : boolean;
  1713.   c       : char;
  1714.  
  1715. begin
  1716.   okset := ([':','_','.','\'] + ['A'..'Z'] + ['0'..'9']);
  1717.   get_dir;
  1718.   repeat
  1719.     clrscr;
  1720.     write(v); name := '';
  1721.     getstring (name,okset);
  1722.     if (length(name)=0) then begin
  1723.       window (1,1,80,25); exit;
  1724.     end;
  1725.     rename (name);
  1726.     assign(f,name);
  1727. {$i-} reset(f); {$i+}
  1728.     ok := (ioresult=0);
  1729.     if not ok then begin
  1730.       writeln; video (30);
  1731.       writeln (beep,'ERROR --- ',name,' not on disk'); video(15);
  1732.       ok := false; delay(2000);
  1733.     end; { if file exist }
  1734.   until ok;
  1735.   close (f);
  1736.   window (1,1,80,25);
  1737. end;
  1738.  
  1739. procedure merge;
  1740. var
  1741.   i,num,j     : integer;
  1742.   f1,f2       : text;
  1743.   line1,line2 : string[255];
  1744.   eof1,eof2   : boolean;
  1745.   grades      : array [0 .. 100] of integer;
  1746.   stuname,stuname2      : stringtype;
  1747.   qa,la,ha,ta,final,ave : real;
  1748.   q,l,h,t,fin,av : real;
  1749.  
  1750. begin
  1751.   clrscr;
  1752.   get_file ('File to merge --> ');
  1753.   if length (name)=0 then exit;
  1754.   assign (f1,name);
  1755.   get_file ('File to merge --> ');
  1756.   assign (f2,name);
  1757.   files;
  1758.   reset(f1); reset(f2); rewrite (f);
  1759.   eof1 := false; eof2 := false;
  1760.   if eof(f1) then eof1 := true;
  1761.   if eof(f2) then eof2 := true;
  1762.   if not eof1 then  readln (f1,stuname,ha,qa,la,ta,final,ave);
  1763.   if not eof2 then  readln (f2,stuname2,h,q,l,t,fin,av);
  1764.   while not eof1 and not eof2 do begin
  1765.     if (stuname<=stuname2) then begin
  1766.       writeln (f,stuname:20,ha:5:1,qa:6:1,la:6:1,ta:6:1,final:7:1,ave:9:1);
  1767.       readln (f1,stuname,ha,qa,la,ta,final,ave);
  1768.       if eof(f1) then eof1 := true;
  1769.     end
  1770.     else begin
  1771.       writeln (f,stuname2:20,h:5:1,q:6:1,l:6:1,t:6:1,fin:7:1,av:9:1);
  1772.       readln (f2,stuname2,h,q,l,t,fin,av);
  1773.       if eof(f2) then eof2 := true;
  1774.     end;
  1775.   end; { while }
  1776.  
  1777.   if eof2 then begin
  1778.     while not eof1 do begin
  1779.       if (stuname>stuname2) and eof2 then begin
  1780.         eof2 := false;
  1781.         writeln (f,stuname2:20,h:5:1,q:6:1,l:6:1,t:6:1,fin:7:1,av:9:1);
  1782.         stuname2 := '{';
  1783.       end
  1784.       else begin
  1785.         writeln (f,stuname:20,ha:5:1,qa:6:1,la:6:1,ta:6:1,final:7:1,ave:9:1);
  1786.         readln (f1,stuname,ha,qa,la,ta,final,ave);
  1787.         if eof(f1) then eof1 := true;
  1788.       end
  1789.     end; { while }
  1790.  
  1791.     if (stuname2<>'{') then
  1792.       if (stuname<=stuname2) then begin
  1793.         writeln (f,stuname:20,ha:5:1,qa:6:1,la:6:1,ta:6:1,final:7:1,ave:9:1);
  1794.         writeln (f,stuname2:20,h:5:1,q:6:1,l:6:1,t:6:1,fin:7:1,av:9:1);
  1795.       end
  1796.       else begin
  1797.         writeln (f,stuname2:20,h:5:1,q:6:1,l:6:1,t:6:1,fin:7:1,av:9:1);
  1798.         writeln (f,stuname:20,ha:5:1,qa:6:1,la:6:1,ta:6:1,final:7:1,ave:9:1);
  1799.       end
  1800.     else writeln (f,stuname:20,ha:5:1,qa:6:1,la:6:1,ta:6:1,final:7:1,ave:9:1)
  1801.   end { if eof2 }
  1802.  
  1803.   else begin
  1804.     while not eof2 do begin
  1805.       if (stuname<=stuname2) and eof1 then begin
  1806.         eof1 := false;
  1807.         writeln (f,stuname:20,ha:5:1,qa:6:1,la:6:1,ta:6:1,final:7:1,ave:9:1);
  1808.         stuname := '{';
  1809.       end
  1810.       else begin
  1811.         writeln (f,stuname2:20,h:5:1,q:6:1,l:6:1,t:6:1,fin:7:1,av:9:1);
  1812.         readln (f2,stuname2,h,q,l,t,fin,av);
  1813.         if eof(f2) then eof2 := true;
  1814.       end
  1815.     end;
  1816.  
  1817.     if (stuname<>'{') then
  1818.       if (stuname<=stuname2) then begin
  1819.         writeln (f,stuname:20,ha:5:1,qa:6:1,la:6:1,ta:6:1,final:7:1,ave:9:1);
  1820.         writeln (f,stuname2:20,h:5:1,q:6:1,l:6:1,t:6:1,fin:7:1,av:9:1);
  1821.       end
  1822.       else begin
  1823.         writeln (f,stuname2:20,h:5:1,q:6:1,l:6:1,t:6:1,fin:7:1,av:9:1);
  1824.         writeln (f,stuname:20,ha:5:1,qa:6:1,la:6:1,ta:6:1,final:7:1,ave:9:1);
  1825.       end
  1826.     else writeln (f,stuname2:20,h:5:1,q:6:1,l:6:1,t:6:1,fin:7:1,av:9:1);
  1827.   end; { else not eof2 }
  1828.  
  1829.   close (f); close (f1); close(f2);
  1830.   clrscr;
  1831.   write ('Send merged file to printer? ');
  1832.   if yes then begin
  1833.     for i := 1 to 100 do grades[i] := 0;
  1834.     reset (f);
  1835.     writeln (lst,'   NAME              HMWK  QUIZ   LAB  TEST  FINAL  AVERAGE');
  1836.     writeln (lst,'===========================================================');
  1837.     num := 0;
  1838.     repeat
  1839.       readln (f,stuname,ha,qa,la,ta,final,ave);
  1840.       writeln (lst,stuname:20,ha:5:1,qa:6:1,la:6:1,ta:6:1,final:7:1,ave:9:1);
  1841.       num := num + 1;
  1842.       i := round(ave);
  1843.       if (i<=100) and (i>0) then
  1844.         grades [i] := grades[i]+1;
  1845.       if num mod(60) = 0 then begin
  1846.         write(lst,chr(12));
  1847.         writeln (lst,'   NAME              HMWK  QUIZ   LAB  TEST  FINAL  AVERAGE');
  1848.         writeln (lst,'===========================================================');
  1849.       end;
  1850.     until eof(f);
  1851.     writeln (lst);
  1852.     writeln;writeln;
  1853.     write ('Frequency plot? ');
  1854.     if yes then begin
  1855.       write (lst,chr(12));
  1856.       i := 100;
  1857.       while (grades [i] = 0) and (i>0) do
  1858.         i := i-1;
  1859.  
  1860.       while (num>0) and (i>0) do begin
  1861.         write (lst,i,' ',chr(124),' ');
  1862.         for j := 1 to grades [i] do
  1863.           write (lst,'*');
  1864.         writeln (lst);
  1865.         num := num - grades [i];
  1866.         i := i - 1;
  1867.       end; (* while *)
  1868.     end; { if }
  1869.   end; (* if *)
  1870.   close(f);
  1871. end; { merge }
  1872.  
  1873. (******************************* MENUDRIVE *******************************)
  1874.  
  1875. PROCEDURE MENUDRIVE (c : char);
  1876.  
  1877. begin
  1878.   case c of
  1879.     'N' : NAMES;
  1880.     'P' : PRINT;
  1881.     'G' : WHO;
  1882.     'S' : SAVE;
  1883.     'R' : RETRIEVE;
  1884.     'M' : merge;
  1885.   end; (* case *)
  1886. end; (* menudrive *)
  1887.  
  1888. (********************************** MENU *********************************)
  1889.  
  1890. PROCEDURE MENU;
  1891. var
  1892.   i : integer;
  1893.   c : char;
  1894.  
  1895. begin
  1896.   repeat
  1897.   clrscr;
  1898.   writeln;
  1899.   writeln ('GRADE MANAGEMENT SYSTEM   *** Version 3.0 ***');
  1900.   writeln;
  1901.   writeln ('Memory available: ',MEMAVAIL,' PARAGRAPHS');
  1902.   writeln;
  1903.   writeln;
  1904.   writeln ('Choose option from below: ');
  1905.   writeln;
  1906.   writeln ('  N -- names');
  1907.   writeln ('  P -- print');
  1908.   writeln ('  G -- grades');
  1909.   writeln ('  S -- save file to disk');
  1910.   writeln ('  R -- retrieve file from disk');
  1911.   writeln ('  M -- merge files');
  1912.   writeln ('  L -- leave program');
  1913.   writeln;
  1914.   write ('Enter choice: ');
  1915.   c := getchar (['N','P','R','S','G','L','M',#13]);
  1916.  
  1917.   MENUDRIVE (c);
  1918.   until c in (['L']);
  1919. end; (* menu *)
  1920.  
  1921. begin
  1922.   textbackground (4);
  1923.   video (15);
  1924.   INITIALIZE;
  1925.   beep := chr(7);
  1926.   nameset := ['A'..'Z',' ',',','.'];
  1927.   MENU;
  1928. end.